home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / Meshwriter / MeshWriterTest / modules / galaxy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  3.3 KB  |  127 lines

  1. /*
  2. **      $VER: galaxy.c 1.00 (27.3.1999)
  3. **
  4. **      Creation date     : 27.3.1999
  5. **
  6. **      Description       :
  7. **         MeshWriter testprogram shape module.
  8. **
  9. **
  10. **      Written by Stephan Bielmann
  11. **
  12. */
  13.  
  14. /*************************** Includes *******************************/
  15.  
  16. #include <stdlib.h>
  17. #include <math.h>
  18.  
  19. #ifndef WITHMWLLIB
  20. #include "//meshlib.h"
  21. #else
  22. #include <meshwriter/meshwriter.h>
  23. #include <pragma/meshwriter_lib.h>
  24. #endif
  25.  
  26. /**************************** Defines *******************************/
  27.  
  28. #define PI            3.14159265359
  29.  
  30. /*********************** Type definitions ***************************/
  31.  
  32. /********************** Private functions ***************************/
  33.  
  34. static VOID particleadd(ULONG mesh,ULONG material,TOCLFloat size,TOCLVertex position){
  35.   TOCLVertex x,y,z;
  36.  
  37.   x.x=position.x;
  38.   x.y=position.y-size;
  39.   x.z=position.z;
  40.  
  41.   y.x=position.x+size;
  42.   y.y=position.y+size;
  43.   y.z=position.z;
  44.  
  45.   z.x=position.x-size;
  46.   z.y=position.y+size;
  47.   z.z=position.z;
  48.  
  49.   MWLMeshTriangleAdd(mesh,material,&x,&y,&z);
  50. }
  51.  
  52. static FLOAT random(FLOAT range) {
  53.   return((range * rand () / RAND_MAX)-(range/2));
  54. }
  55.  
  56. /********************** Public functions ****************************/
  57.  
  58. /********************************************************************\
  59. *                                                                    *
  60. * Name         : galaxy                                              *
  61. *                                                                    *
  62. * Description  : Draws a galaxy like shape with the help of the      *
  63. *                 rotation function.                                  *
  64. *                                                                    *
  65. * Arguments    : mesh    IN  : An initialized mesh handle.           *
  66. *                                                                    *
  67. * Comment      : This function is an implementation of Nikola        *
  68. *                Smolenski his GalaxyCreator algorithm.              *
  69. *                                                                    *
  70. \********************************************************************/
  71. void galaxy (ULONG mesh) {
  72.   TOCLVertex v,v2;
  73.   TOCLColor color;
  74.   ULONG j,angle,c[25];
  75.   FLOAT Ri,Si,R1,R,i,h;
  76.  
  77.   srand(rand());
  78.  
  79.   for(j=0;j<5;j++) {
  80.     MWLMeshMaterialAdd(mesh,&c[j]);
  81.     color.r=255-j*10,color.g=255-j*10,color.b=255-j*10;
  82.     MWLMeshMaterialDiffuseColorSet(mesh,c[j],&color);
  83.   }
  84.  
  85.   for(j=5;j<25;j++) {
  86.     MWLMeshMaterialAdd(mesh,&c[j]);
  87.     color.r=255-j*10,color.g=255-j*10,color.b=255;
  88.     MWLMeshMaterialDiffuseColorSet(mesh,c[j],&color);
  89.   }
  90.  
  91.   angle=5;
  92.   Ri=0;
  93.   Si=5;
  94.   R1=10;
  95.   h=0;
  96.   for(i=0.2;i<=angle;i+=0.2) {
  97.     Ri+=Si;
  98.     R=random(6)+R1;
  99.     v.x=cos(i)*Ri;v.y=sin(i)*Ri,v.z=0;
  100.     for(j=1;j<=R;j++) {
  101.       v2.x=v.x-random(5);v2.y=v.y-random(5);
  102.       v2.z=random(cos(h)*20);h+=PI/50;
  103.       particleadd(mesh,c[(ULONG)(i/0.2)-1],2,v2);
  104.       v.x+=random(10);v.y+=random(10);
  105.     }
  106.   }
  107.  
  108.   angle=5;
  109.   Ri=0;
  110.   Si=5;
  111.   R1=10;
  112.   h=0;
  113.   for(i=0.2;i<=angle;i+=0.2) {
  114.     Ri+=Si;
  115.     R=random(6)+R1;
  116.     v.x=-cos(i)*Ri;v.y=-sin(i)*Ri,v.z=0;
  117.     for(j=1;j<=R;j++) {
  118.       v2.x=v.x-random(5);v2.y=v.y-random(5);
  119.       v2.z=random(cos(h)*20);h+=PI/50;
  120.       particleadd(mesh,c[(ULONG)(i/0.2)-1],2,v2);
  121.       v.x+=random(10);v.y+=random(10);
  122.     }
  123.   }
  124. }
  125.  
  126. /************************* End of file ******************************/
  127.